package com.atguigu.yygh.hosp.controller;

import com.atguigu.yygh.hosp.result.R;
import com.atguigu.yygh.hosp.service.ScheduleService;
import com.atguigu.yygh.model.hosp.Schedule;
import com.atguigu.yygh.vo.hosp.ScheduleOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/hosp/schedule")
public class ScheduleController {


    @Autowired
    ScheduleService scheduleService;
    /**
     * 根据Mongodb排班的id,查询排班数据,封装成ScheduleOrderVo对象
     * 该对象中包括了调用医院端接口时和创建平台端订单时所需要的数据
     */
    @GetMapping("/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable String scheduleId){
        return scheduleService.getScheduleOrderVo(scheduleId);
    }



    /**
     * 根据排班的id查询排班
     */
    @GetMapping("/getSchedule/{id}")
    public R getSchedule(@PathVariable String id){
        Schedule schedule = scheduleService.getSchedule(id);
        return R.ok().data("schedule",schedule);
    }

    /**
     * 根据医院编号+科室编号+排班日期  查询排班列表
     * 点击日期方块时,查询排班列表
     */

    @GetMapping("/getScheduleDetail/{hoscode}/{depcode}/{workDate}")
    public R getScheduleDetail(@PathVariable String hoscode,@PathVariable String depcode,@PathVariable String workDate){

     List<Schedule> list = scheduleService.getScheduleDetail(hoscode,depcode,workDate);
        return R.ok().data("list",list);
    }



    /**
     * 针对指定医院+科室下的排班按照workDate分组聚合,每一组需要提取的数据:
     */
    @GetMapping("/getScheduleBookingRule/{pageNum}/{pageSize}/{hoscode}/{depcode}")
    public R getScheduleBookingRule(@PathVariable Long pageNum, @PathVariable Long pageSize,@PathVariable String hoscode,@PathVariable String depcode){
        Map map = scheduleService.getScheduleBookingRule(pageNum,pageSize,hoscode,depcode);
        return R.ok().data(map);
    }

}
